<?php
require_once(dirname(__FILE__) . '/PortalUtil.class.php');

class LogAccess extends PortalUtil {
	public $tbl = Constant::tbl_log_access;

	function __construct() {
		$request['update'] = '$Date: 2009/02/16 07:36:07 $';
		$request['revision'] = '$Revision: 1.1 $';

		parent::__construct($request);
		
		$this->dsn = 'test';
		$this->dsn_r = 'test';
		$this->dsn_w = 'test';
	}
	
	function _insert($request) {
		
		$action = $request['do'];
		$uri = $_SERVER["PHP_SELF"];
		$query = $_SERVER["QUERY_STRING"];
		
		$ip	= $_SERVER['REMOTE_ADDR'];
		$ua = $_SERVER['HTTP_USER_AGENT'];
		
		$content = json_encode($request);
	
		$totaltime = $this->totaltime($request);
	
		$db = newdb($this->dsn_w);
		$fmt = "INSERT INTO %s(uri, action, query, content, totaltime, ip, ua, createtime) ";
		$fmt .= "VALUES('%s', '%s', '%s', '%s', '%s', '%s', '%s', NOW())";
		$sql = sprintf($fmt, $this->tbl, $uri, $action, $query, $content, $totaltime, $ip, $ua);
		// debug($sql);
		$db->query($sql);
	}
	
	function totaltime($request) {
		$endtime = cur_time();
		$totaltime = $endtime - $request['starttime'];
	
		return number_format($totaltime, 7);
	}
}
?>
